package controller.user;

import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import pojo.Backenduser;
import service.user.UserService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("user")
public class UserController {
    @Resource
    private UserService userService;

    //进入后台登录页面
    @RequestMapping("/jing")
    public String jing(){
        return "login";
    }


    //登入后台管理系统
    @RequestMapping("/getLoginUser")
    public  String getLoginUser(@Param("userCode") String userCode, @Param("userPassword") String userPassword, HttpSession session, HttpServletRequest request){
        Backenduser user=new Backenduser();
        try{
            user=userService.getLoginUser(userCode,userPassword);
        }catch (Exception e){
            e.printStackTrace();
        }
        if(null!=user){
          session.setAttribute("user",user);
            return "index";
        }
        else{
            request.setAttribute("error","用户名或密码不正确");
            return "login";
        }
    }
    //注销
    @RequestMapping("/tozhuxiao")
    public String tozhuxiao(HttpSession session){
        session.setAttribute("user",null);
        session.removeAttribute("user");
        session.setAttribute("devuser",null);
        session.removeAttribute("devuser");
        return "redirect:/index.jsp";
    }

}
